package xin.yangshuai.springsecurity01.hello;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.DelegatingPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.util.Assert;

/**
 * Main
 *
 * @author shuai
 * @date 2025/2/18
 */
public class Main {
    public static void main(String[] args) {

        // 工作因子，默认10，最小4，最大31，值越大运算速度越慢
        PasswordEncoder encoder = new BCryptPasswordEncoder(10);

        String result = encoder.encode("password");
        System.out.println(result);

        Assert.isTrue(encoder.matches("password", result), "密码不一致");


        encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();

        result = encoder.encode("password");
        System.out.println(result);

        Assert.isTrue(encoder.matches("password", result), "密码不一致");


    }
}
